﻿#pragma strict

var inside : AudioClip;
var outside : AudioClip;
var chime : AudioClip;

private var audioOutside: AudioSource;
private var audioInside: AudioSource;
private var audioChime: AudioSource;
private var isInside = false;
function Start () {
	var insideAudio = gameObject.AddComponent(AudioSource);
	insideAudio.clip = inside;
	insideAudio.loop = true;
	insideAudio.playOnAwake = true;
	insideAudio.volume = 0.1;
	
	var chimeAudio = gameObject.AddComponent(AudioSource);
	chimeAudio.clip = chime;
	chimeAudio.loop = false;
	chimeAudio.playOnAwake = true;
	chimeAudio.volume = 0.1;
	
	var outsideAudio = gameObject.AddComponent(AudioSource);
	outsideAudio.clip = outside;
	outsideAudio.loop = true;
	outsideAudio.playOnAwake = true;
	outsideAudio.volume = .2;
	
	audioOutside = outsideAudio;
	
	audioInside = insideAudio;
	audioChime = chimeAudio;
	
	audioOutside.Play();
	
	
}

function Update () {
	var x = transform.position.x;
	var z = transform.position.z;
	if(x > 1 && x < 13 && z < 1 && z > -13){
		if(!isInside){
			print("here");
			audioOutside.Stop();
			audioChime.Play();
			audioInside.Play();
			
			
			isInside = true;
		} 
		
	} else {
	if ( isInside )
       {
       	print("outside");
         audioInside.Stop();
         audioChime.Play();
         audioOutside.Play();
         isInside = false;
       }
	}
	
	
}